package com.cskaoyan;

import com.cskaoyan.bean.Teacher;
import com.cskaoyan.mapper.TeacherMapper;
import com.cskaoyan.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;

/**
 * 创建日期: 2022/08/01 15:22
 *
 * @author ciggar
 */
public class MybatisMain {

    static SqlSession sqlSession;
    static TeacherMapper teacherMapper;

    static {
        sqlSession = MybatisUtils.getSqlSession(true);
        teacherMapper = sqlSession.getMapper(TeacherMapper.class);
    }


    public static void main1(String[] args) {

        String name = teacherMapper.selectNameById(3001);

        System.out.println(name);

    }

    public static void main2(String[] args) {

        int affectedRows = teacherMapper.updateTeacherNameById("马冬梅", 3001);

        System.out.println(affectedRows);

    }

    public static void main3(String[] args) {

        Teacher teacher = new Teacher();
        teacher.setId(5001);
        teacher.setName("马超");
        teacher.setNickname("奋威将军");
        teacher.setGender("male");


        int affectedRows = teacherMapper.insertTeacher(teacher);

        System.out.println(affectedRows);

    }

    public static void main4(String[] args) {

        Teacher teacher = new Teacher();
        teacher.setId(6001);
        teacher.setName("宋江");
        teacher.setNickname("及时雨");
        teacher.setGender("male");


        int affectedRows = teacherMapper.insertTeacherWithParam(teacher);

        System.out.println(affectedRows);

    }


    public static void main6(String[] args) {

        Teacher teacher = new Teacher();
        teacher.setName("晁盖");
        teacher.setNickname("晁天王");
        int affectedRows = teacherMapper.updateTeacherById(6001, teacher);

        System.out.println(affectedRows);


    }


    public static void main7(String[] args) {

        HashMap<String, Object> hashMap = new HashMap<>();


        hashMap.put("id",6002);
        hashMap.put("name","李逵");
        hashMap.put("nickname","天杀星");
        hashMap.put("gender","male");


        int affectedRows = teacherMapper.insertTeacherByMap(hashMap);

        System.out.println(affectedRows);

    }



    public static void main8(String[] args) {

        int affectedRows = teacherMapper.insertTeacher2(6004, "花荣", "小李广", "male");

        System.out.println("affectedRows:" + affectedRows);

    }

    public static void main9(String[] args) {

        Teacher teacher = teacherMapper.selectTeacherById$(6001);

        System.out.println(teacher);

    }

    public static void main10(String[] args) {


        Teacher teacher = teacherMapper.selectTeacherByIdAndTableName(6001, "teacher2");

        System.out.println(teacher);
    }


    public static void main(String[] args) {

        Teacher teacher = teacherMapper.selectTeacherByName("晁盖");

        System.out.println(teacher);

    }





}
